# import subprocess
# import logging
# from log import logger
# from main import client
#
#
#
#
# class ShellCmd(object):
#     '''
#     classdocs
#     '''
#
#     def __init__(self, cmd, workdir=None, logcmd=True):
#         '''
#         Constructor
#         '''
#         self.cmd = cmd
#         self.client = client
#         self.logcmd = logcmd
#         self.workdir = workdir
#         self.stdout = None
#         self.stderr = None
#         self.return_code = None
#
#     def debug_error(self):
#         err = []
#         err.append('failed to execute shell command: %s' % self.cmd)
#         err.append('stdout: %s' % self.stdout)
#         err.append('stderr: %s' % self.stderr)
#         message = '\n'.join(err)
#         logger.debug('execute error %s' % message)
#
#     def __call__(self, is_exception=True, timeout=5):
#         _, self.stdout, self.stderr = self.client.exec_command(self.cmd)
#         self.stdout = self.stdout.decode().strip()
#         if self.logcmd:
#             logger.debug(self.cmd)
#             if self.stderr:
#                 logger.debug('command return error result : %s' % self.stderr)
#             else:
#                 logger.debug('command return ok result : %s' % self.stdout)
#
#         self.return_code = 1 if self.stderr else 0
#         return self
#
#
# def call(cmd, exception=True, workdir=None, logcmd=True):
#     return ShellCmd(cmd, workdir, logcmd=logcmd)(exception)
#
#
# def run(cmd, workdir=None):
#     s = ShellCmd(cmd, workdir)
#     s(False)
#     return s.return_code
